package ledger

import (
	"jlpay-sdk-go/pkg/jlpay/core"
	"jlpay-sdk-go/pkg/jlpay/models/ledger"
	"jlpay-sdk-go/pkg/jlpay/services"
)

// MerchconfService 商户配置服务
type MerchconfService struct {
	*services.BaseService
}

// NewMerchconfService 创建商户配置服务
func NewMerchconfService(config *core.Config) *MerchconfService {
	return &MerchconfService{
		BaseService: services.NewBaseService(config),
	}
}

// QueryMerchRev 查询商户分账信息
func (s *MerchconfService) QueryMerchRev(request *ledger.MerchRevQueryRequest) (*ledger.MerchRevQueryResponse, error) {
	response := ledger.NewMerchRevQueryResponse()
	err := s.Post(request, response, "/open/ledger/merch/rev/query")
	if err != nil {
		return nil, err
	}
	return response, nil
}

// UnbindMerchRev 解绑商户分账
func (s *MerchconfService) UnbindMerchRev(request *ledger.MerchRevUnbindRequest) (*ledger.MerchRevUnbindResponse, error) {
	response := ledger.NewMerchRevUnbindResponse()
	err := s.Post(request, response, "/open/ledger/merch/rev/unbind")
	if err != nil {
		return nil, err
	}
	return response, nil
}

// UploadMerchFile 上传商户文件
func (s *MerchconfService) UploadMerchFile(request *ledger.MerchFileUploadRequest) (*ledger.MerchFileUploadResponse, error) {
	response := ledger.NewMerchFileUploadResponse()
	err := s.Post(request, response, "/open/ledger/merch/file/upload")
	if err != nil {
		return nil, err
	}
	return response, nil
}

// OpenMerchIssue 开通商户分账
func (s *MerchconfService) OpenMerchIssue(request *ledger.MerchIssueOpenRequest) (*ledger.MerchIssueOpenResponse, error) {
	response := ledger.NewMerchIssueOpenResponse()
	err := s.Post(request, response, "/open/ledger/merch/issue/open")
	if err != nil {
		return nil, err
	}
	return response, nil
}

// QueryMerchIssue 查询商户分账
func (s *MerchconfService) QueryMerchIssue(request *ledger.MerchIssueQueryRequest) (*ledger.MerchIssueQueryResponse, error) {
	response := ledger.NewMerchIssueQueryResponse()
	err := s.Post(request, response, "/open/ledger/merch/issue/query")
	if err != nil {
		return nil, err
	}
	return response, nil
}

// UpdateMerchIssue 更新商户分账
func (s *MerchconfService) UpdateMerchIssue(request *ledger.MerchIssueUpdateRequest) (*ledger.MerchIssueUpdateResponse, error) {
	response := ledger.NewMerchIssueUpdateResponse()
	err := s.Post(request, response, "/open/ledger/merch/issue/update")
	if err != nil {
		return nil, err
	}
	return response, nil
}

// UpdateMerchRevSettle 更新商户分账结算
func (s *MerchconfService) UpdateMerchRevSettle(request *ledger.MerchRevSettleUpdateRequest) (*ledger.MerchRevSettleUpdateResponse, error) {
	response := ledger.NewMerchRevSettleUpdateResponse()
	err := s.Post(request, response, "/open/ledger/merch/rev/settle/update")
	if err != nil {
		return nil, err
	}
	return response, nil
}

// QueryMerchRevBind 查询商户分账绑定
func (s *MerchconfService) QueryMerchRevBind(request *ledger.MerchRevBindQueryRequest) (*ledger.MerchRevBindQueryResponse, error) {
	response := ledger.NewMerchRevBindQueryResponse()
	err := s.Post(request, response, "/open/ledger/merch/rev/bind/query")
	if err != nil {
		return nil, err
	}
	return response, nil
}

// BindMerchRev 绑定商户分账
func (s *MerchconfService) BindMerchRev(request *ledger.MerchRevBindRequest) (*ledger.MerchRevBindResponse, error) {
	response := ledger.NewMerchRevBindResponse()
	err := s.Post(request, response, "/open/ledger/merch/rev/bind")
	if err != nil {
		return nil, err
	}
	return response, nil
}

// OpenMerchRev 开通商户分账
func (s *MerchconfService) OpenMerchRev(request *ledger.MerchRevOpenRequest) (*ledger.MerchRevOpenResponse, error) {
	response := ledger.NewMerchRevOpenResponse()
	err := s.Post(request, response, "/open/ledger/merch/rev/open")
	if err != nil {
		return nil, err
	}
	return response, nil
}
